package com.dferreira.axil.data;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import com.dferreira.axil.model.Fornecedor;

@RequestScoped
public class ListaDeFornecedores {

    @Inject
    private RepositorioDeFornecedores repositorio;

    private List<Fornecedor> fornecedores;

    @Produces
    @Named
    public List<Fornecedor> getFornecedores() {
        return fornecedores;
    }

    public void quandoAlterarListaDeFornecedores(@Observes(notifyObserver = Reception.IF_EXISTS) final Fornecedor fornecedor) {
    	recuperarFornecedores();
    }

    @PostConstruct
    public void recuperarFornecedores() {
        fornecedores = repositorio.findAllOrderedByName();
    }
}
